var Loader = require("./loader");
var Log = require("./log");
var Path = require("path");

function HandlerService(){
    this.handlers = {};
}

HandlerService.prototype.start = function(){
    this.handlers = Loader.load(Path.join(app.getPath(),'handlers'));
    //Log.debug("Handlers loaded, handlers = %s",JSON.stringify(this.handlers));
};

HandlerService.prototype.isRegisteredMsg = function(msg){
    var id = msg.id + "Handler";
    if(this.handlers.hasOwnProperty(id)){
        return true;
    }
    return false;
};

HandlerService.prototype.handleMsg = function(session,msg){
    if(this.isRegisteredMsg(msg)){
        var id = msg.id + "Handler";
        var ret = this.handlers[id](session,msg);
        return ret;
    }
    return null;
};

module.exports = HandlerService;